package net.yebaihe.wc;

import java.util.ArrayList;
import java.util.HashMap;

import com.feedback.NotificationType;
import com.feedback.UMFeedbackService;

import net.yebaihe.sdk.SdkUtils;
import net.yebaihe.wc.DataMan.MSGTYPE;
import android.app.AlertDialog;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class IndexSub extends StateMachine{

	@Override
	protected String getTopbarTitle() {
		return "更多";
	}

	@Override
	protected void prepareClient(View client) {
		UMFeedbackService.enableNewReplyNotification(this, NotificationType.AlertDialog);
		ListView listview = (ListView) client.findViewById(R.id.listsubitems); 
		ArrayList<HashMap<String, Object>> meumList = new ArrayList<HashMap<String, Object>>(); 

		String idxBtnTitles[]={
			"个人资料",
			"切换城市",
			"意见反馈",
			"关于微餐",
		};
		int idxBtnImages[]={
				R.drawable.more1,
				R.drawable.more2,
				R.drawable.more3,
				R.drawable.more4,
			};
		
		for(int i = 1;i < idxBtnTitles.length+1;i++) { 
			HashMap<String, Object> map = new HashMap<String, Object>(); 
			map.put("title", idxBtnTitles[i-1]); 
			map.put("img", idxBtnImages[i-1]); 
			map.put("cnt", ">"); 
			meumList.add(map); 
		} 

		SimpleAdapter saMenuItem = new SimpleAdapter(this, 
				meumList, //数据源 
				R.layout.indexsub_item, //xml实现 
				new String[]{"img","title","cnt"}, //对应map的Key 
				new int[]{R.id.imgsubitem,R.id.txtItem,R.id.txtCnt});  //对应R的Id 

		//添加Item到网格中 
		listview.setAdapter(saMenuItem); 
		listview.setOnItemClickListener(new OnItemClickListener() { 
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) { 
				switch(arg2){
				case 0:{
					if ((getWCAppContext().email==null) || (getWCAppContext().email.length()<=0)){
						Toast.makeText(IndexSub.this, "您还没有登录!", Toast.LENGTH_LONG).show();
						changeToActivity(Login.class);
						return;
					}
					changeToActivity(UserInfo.class);
				}
					break;
				case 1:{
					changeToActivity(Cities.class);
					break;
				}
				case 2:{
					UMFeedbackService.openUmengFeedbackSDK(IndexSub.this);
					break;
				}
				case 3:{
					new AlertDialog.Builder(IndexSub.this).setTitle(getString(R.string.app_name))
						.setMessage("版本："+SdkUtils.getAppVersionName(IndexSub.this)+"\n科技服务生活").setIcon(R.drawable.icon).create().show();
				}
					break;
				}
			} 
		} 
				); 
	}

	@Override
	public void HandleMessage(MSGTYPE msgtype, boolean ret,
			HashMap<String, String> params) {
		super.HandleMessage(msgtype, ret, params);
	}

	@Override
	protected int getLayoutRes() {
		return R.layout.indexsub;
	}

}
